package com.falcon.file.controller;

import com.falcon.file.service.IFileService;
import com.falcon.core.controller.IBaseController;
import com.falcon.core.domain.BaseResponse;
import com.falcon.core.domain.PagerResponse;
import com.falcon.file.domain.dos.FileDO;
import com.falcon.file.domain.req.FileQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/file/file")
@Tag(name = "FileManagerController", description = "文件管理-接口")
public class FileController implements IBaseController {

    @Autowired
    private IFileService fileService;

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> delete(@PathVariable Long id) {

        Boolean success =  this.fileService.deleteById(id);

        return BaseResponse.success(success);
    }

    @GetMapping("/{id}")
    public BaseResponse<FileDO> detail(@PathVariable Long id) {

        FileDO userDO =  this.fileService.queryInfoById(id);

        return BaseResponse.success(userDO);
    }

    @PostMapping("/list")
    public BaseResponse<List<FileDO>> list(@RequestBody FileQuery request) {

        List<FileDO> list =  this.fileService.queryList(request);

        return BaseResponse.success(list);
    }

    @PostMapping("/pager")
    public PagerResponse<FileDO> pager(@RequestBody FileQuery request) {

        PagerResponse<FileDO> pager =  this.fileService.queryPager(request);

        return pager;
    }

}

